package com.xcm.controller.client;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xcm.core.annotation.ClientPermissionRequired;
import com.xcm.model.dto.DeviceGroupDTO;
import com.xcm.service.DeviceInfoService;

/**
 * 
 * <p>Title: DeviceContoller</p>  
 * <p>Description: 查询终端所属信息</p>  
 * @author huangf 
 * @date 2018年4月19日
 */
@Controller
@ClientPermissionRequired
@RequestMapping(value = "/client")
public class DeviceContoller {
	
	@Autowired
	private DeviceInfoService deviceInfoService;
	
	/**
	 * 查询所有终端分组code
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/deviceGroups",method =RequestMethod.POST) 
	public Object getAllGroups() {
		List<DeviceGroupDTO> groups = deviceInfoService.getAllGroups();
		Map<String,Object> map = new HashMap<>();
		map.put("code", 0);
		map.put("data", groups);
		map.put("msg", "success");
		return map;
	}
	
	/**
	 * 根据分组code码获取该分组下所有的在线设备的deviceId
	 * @param groupCode
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getOnlineDeviceByGroupCode",method =RequestMethod.POST) 
	public Object getAllGroups(String groupCode) {
		List<String> onlineDeviceNums = deviceInfoService.getOnLineDeviceNumByGroup(groupCode);
		Map<String,Object> map = new HashMap<>();
		map.put("code", 0);
		map.put("data", onlineDeviceNums);
		map.put("msg", "success");
		return map;
	}
	
}
